package com.jkl.controller.home;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jkl.entity.BaseResponseDTO;
import com.jkl.entity.home.HomeRequestEntity;
import com.jkl.entity.home.HomeResponseEntity;
import com.jkl.service.home.mainIndexInter.MainIndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author zjj
 * @date 2019/9/2 08:53
 * @Description ${描述一个类的相关信息}
 */
@RestController
@RequestMapping("/jky/home/index")
@Slf4j
public class MainIndexController {
    @Autowired
    MainIndexService mainIndexService;

    /**
     * 城镇垃圾产生量
     */
    @PostMapping("/cityGarbargeTotal")
    public BaseResponseDTO getProductionAmountAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        HomeResponseEntity productionAmountAnalysis = mainIndexService.getProductionAmountAnalysis(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(productionAmountAnalysis));
        returnData.setReturnData(jsonObject);
        return returnData;
    }

    /**
     * 城镇垃圾产生量和累计同比增长率
     */
    @PostMapping("/cityGarbargeTotalAndRate")
    public BaseResponseDTO getCityGarbageAndRate(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        HomeResponseEntity cityGarbageAndRate = mainIndexService.getCityGarbageAndRate(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(cityGarbageAndRate));
        returnData.setReturnData(jsonObject);
        return returnData;
    }

    /**
     * 无害化处理率
     */
    @PostMapping("/harmlessRate")
    public BaseResponseDTO getHarmLessRateAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        HomeResponseEntity harmLessRateAnalysis = mainIndexService.getHarmLessRateAnalysis(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(harmLessRateAnalysis));
        returnData.setReturnData(jsonObject);
        return returnData;
    }

    /**
     * 近一年各个垃圾产生量和占比
     */
    @PostMapping("/circleAnalysis")
    public BaseResponseDTO getHarmLesscircleAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        HomeResponseEntity harmLesscircleAnalysis = mainIndexService.getHarmLesscircleAnalysis(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(harmLesscircleAnalysis));
        returnData.setReturnData(jsonObject);
        return returnData;
    }

    /**
     * 资源化分析柱状图
     */
    @PostMapping("/resourceAnalysis")
    public BaseResponseDTO getResourceAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        HomeResponseEntity resourceAnalysis = mainIndexService.getResourceAnalysis(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(resourceAnalysis));
        returnData.setReturnData(jsonObject);
        return returnData;
    }

    /**
     * 资源化分析饼状图
     */
    @PostMapping("/resourceCircleAnalysis")
    public BaseResponseDTO getResourceCircleAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        HomeResponseEntity resourceCircleAnalysis = mainIndexService.getResourceCircleAnalysis(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(resourceCircleAnalysis));
        returnData.setReturnData(jsonObject);
        return returnData;


    }

    /**
     * 设施概况
     */
    @PostMapping("/deviceCount")
    public BaseResponseDTO getDeviceCount(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        Map<String, Object> deviceCount = mainIndexService.getDeviceCount(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(deviceCount));
        returnData.setReturnData(jsonObject);
        return returnData;
    }

    /**
     * gis展示
     */
    @PostMapping("/gis")
    public BaseResponseDTO getGisAnalysis(@RequestBody HomeRequestEntity homeRequestEntity) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        HomeResponseEntity gisAnalysis = mainIndexService.getGisAnalysis(homeRequestEntity);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(gisAnalysis));
        returnData.setReturnData(jsonObject);
        return returnData;
    }
}
